package cn.iocoder.yudao.module.data.dal.mysql.dscategory;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.data.dal.dataobject.dscategory.DsCategoryDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.data.controller.admin.dscategory.vo.*;

/**
 * 分类 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface DsCategoryMapper extends BaseMapperX<DsCategoryDO> {

    default PageResult<DsCategoryDO> selectPage(DsCategoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DsCategoryDO>()
                .likeIfPresent(DsCategoryDO::getName, reqVO.getName())
                .eqIfPresent(DsCategoryDO::getDescription, reqVO.getDescription())
                .eqIfPresent(DsCategoryDO::getType, reqVO.getType())
                .eqIfPresent(DsCategoryDO::getPid, reqVO.getPid())
                .eqIfPresent(DsCategoryDO::getEditType, reqVO.getEditType())
                .eqIfPresent(DsCategoryDO::getConfiguration, reqVO.getConfiguration())
                .betweenIfPresent(DsCategoryDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(DsCategoryDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DsCategoryDO::getQrtzInstance, reqVO.getQrtzInstance())
                .eqIfPresent(DsCategoryDO::getTaskStatus, reqVO.getTaskStatus())
                .eqIfPresent(DsCategoryDO::getEnableDataFill, reqVO.getEnableDataFill())
                .orderByDesc(DsCategoryDO::getId));
    }

    default List<DsCategoryDO> selectList(DsCategoryRespVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DsCategoryDO>()
                .likeIfPresent(DsCategoryDO::getName, reqVO.getName())
                .eqIfPresent(DsCategoryDO::getStatus, reqVO.getStatus()));
    }


    default DsCategoryDO selectByParentIdAndName(Long parentId, String name) {
        return selectOne(DsCategoryDO::getPid, parentId, DsCategoryDO::getName, name);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(DsCategoryDO::getPid, parentId);
    }

    default List<DsCategoryDO> selectListByParentId(Collection<Long> parentIds) {
        return selectList(DsCategoryDO::getPid, parentIds);
    }

}